from PIL import Image
from PIL import ImageFilter
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = [u'SimHei']
plt.rcParams['axes.unicode_minus'] = False
import os

def two_color(image,percente):
    array = np.array(image)
    threshold = np.percentile(array, percente)
    table = []
    for i in range(256):
        if i < threshold:
            table.append(0)
        else:
            table.append(1)
    # 图片二值化
    photo = image.point(table, '1').convert('L')
    return photo
def dealimg(image,per):
    width,height = Img.size[0],Img.size[1]
    cutsize = int(width/3)
    full_Img = Image.new('L',Img.size,0)
    part_left = two_color(Img.crop((0,0,cutsize,height)),per)
    part_right = two_color(Img.crop((width-cutsize,0,width,height)),per)
    full_Img.paste(part_left,(0,0,cutsize,height))
    full_Img.paste(part_right,(width-cutsize,0,width,height))
    return full_Img
def findline(image):
    array = np.array(image)
    for i in range(0,len(array),200):
        part1 = False
        part2 = False
        left = -1
        right = -1
        start = -1
        end = -1
        count = 0
        for j in range(0,len(array[i])):
            if array[i][j] ==255:
                count+=1
                start = j
                part1 = True
            # else:
            #     if count>=100:

pics_f = r'F:\公司\桥头跳\宁波桥头跳检测\418整理后数据\采集图像'
data_f = r'F:\公司\桥头跳\宁波桥头跳检测\418整理后数据\数据文件'
files1 = os.listdir(data_f)
files2 = os.listdir(pics_f)
count = 0
for file in files1:
    if file.rstrip('.csv') not in files2:
        count+=1
        print(file)
print(count)
# for file in files2:
#     tar = file.rstrip('.csv').replace('  ',' ')
#     os.rename(os.path.join(pics_f,file),os.path.join(pics_f,tar))



